package com.huang.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/*
*    futureTask  是Runnable的一个实现类
*
* // callable有缓存 执行一次
*
* */
public class callableTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        myThread myThread = new myThread();
        FutureTask futureTask = new FutureTask(myThread);
        new Thread(futureTask,"A").start();
        new Thread(futureTask,"B").start();
        new Thread(futureTask,"C").start();
        Integer o = (Integer) futureTask.get();//获取callable的返回值  获取值会阻塞 放在最后面获取
        System.out.println(o);

    }
}
class myThread implements Callable<Integer> {

    @Override
    public Integer call()  {
        System.out.println("call----");
        return 1024;
    }
}

